package com.baic.ibase.controller.api.v1;


import com.baic.ibase.models.req.AuthLoginReq;
import com.baic.ibase.models.req.common.ApiResponse;
import com.baic.ibase.models.vo.AuthLoginResp;
import com.baic.ibase.service.users.AuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/v1/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * @api {POST} /api/v1/auth/login 登录
     * @apiVersion 1.0.0
     * @apiGroup AuthController
     * @apiName login()
     * @apiParam (请求体) {String} username 用户名
     * @apiParam (请求体) {String} password 密码
     * @apiParam (请求体) {String} phone
     * @apiParam (请求体) {String} email
     * @apiParam (请求体) {String} code
     * @apiParamExample 请求体示例
     * {"password":"VDEKcjN1q","code":"ruvtP","phone":"Mj5FKmW","email":"uvWCeToJRB","username":"j"}
     * @apiSuccess (响应结果) {Number} code
     * @apiSuccess (响应结果) {String} message
     * @apiSuccess (响应结果) {String} errors
     * @apiSuccess (响应结果) {String} traceId
     * @apiSuccess (响应结果) {Boolean} success
     * @apiSuccess (响应结果) {Object} data
     * @apiSuccess (响应结果) {String} data.UserId
     * @apiSuccess (响应结果) {String} data.UserName
     * @apiSuccess (响应结果) {String} data.Token
     * @apiSuccessExample 响应结果示例
     * {"traceId":"5t","code":2915,"data":{"UserName":"FX51","UserId":"Ac1r","Token":"H85"},"success":true,"message":"tvKei","errors":"sbSxJZTqvp"}
     */
    @PostMapping("/login")
    public ApiResponse<AuthLoginResp> login(@RequestBody AuthLoginReq loginReq) {
        ApiResponse<AuthLoginResp> login = authService.login(loginReq);
        log.info("login:{}", login);
        return login;
    }

    @PostMapping("/logout")
    public ApiResponse<Boolean> logout() {
        return authService.logout();
    }


}
